var a = require("../../../@babel/runtime/helpers/toConsumableArray"), e = getApp().globalData.api, t = getApp();

Page({
    data: {
        isSearch: !1,
        isSearchEnd: !1,
        searchValue: "",
        defaultValue: "搜索医院",
        defaulValueBool: !1,
        hotHosList: null,
        hotCategoryList: null,
        hosList: null,
        pkgList: null,
        historySearch: []
    },
    onLoad: function(a) {
        a.search && this.setData({
            defaultValue: a.search,
            defaulValueBool: !0,
            isSearch: !0
        }); 
        // this.getHotList();
    },
    onShow: function() {
        
    },
     
   
    go: function(a) {
        var e = a.currentTarget.dataset.url.split("/");
        e = e[e.length - 1], t.globalData.jumpPkgList.isJumpPkgList = !0, t.globalData.jumpPkgList.requestParamsUrl = e, 
        wx.switchTab({
            url: "/pages/packagelists/packagelists",
            success: function(a) {
                var e = getCurrentPages().pop();
                null != e && null != e && e.onLoad();
            }
        });
    },
    getSearchDataList: function() {
        var a = this.data.searchValue;
        if (0 != a.length && a) {
            var t = this, s = {
                keyword: this.data.searchValue,
                areacode: getApp().globalData.selectedCityAreaCode
            };
            e.post1("wechat/home/_comsearchByhos", s, !1).then(function(a) {
                "1" == a.code && (a.data.hosarr.map(function(a, e) {
                    new RegExp("<b");
                    return a;
                }), 
              
                t.setData({
                    hosList: a.data.hosarr.length > 0 ? a.data.hosarr : [],
                   
                })), t.setData({
                    isSearchEnd: !0
                });
            }, function(a) {
                console.log(a), t.setData({
                    isSearchEnd: !0
                }),  "0" == a.code && wx.showToast({
                    title: a.msg,
                    icon: "none"
                });
            });
        }
    },
    hotHospitalTap: function(a) {
        wx.navigateTo({
            url: "/pages/hospitalinfo/hospitalinfo?domain=".concat(a.currentTarget.dataset.item.searchParams.domain, "&areaCode=").concat(a.currentTarget.dataset.item.searchParams.areaCode)
        });
    },
    hotPkgTap: function(a) {
        t.globalData.jumpPkgList.isJumpPkgList = !0, t.globalData.jumpPkgList.requestParamsUrl = a.currentTarget.dataset.item.searchParams.requestParamsUrl;
        wx.switchTab({
            url: "/pages/packagelists/packagelists",
            success: function(a) {
                var e = getCurrentPages().pop();
                null != e && null != e && e.onLoad();
            }
        });
    },
    hisTo: function(a) {
        var e = "/pages/homepages/search/result/result?search=" + a.currentTarget.dataset.item;
        wx.navigateTo({
            url: e
        });
    },
    searchHospitalTap: function(a) {
        console.log(a)
        wx.navigateTo({
            url: "/pages/hospitalinfo/hospitalinfo?domain="+a.currentTarget.dataset.item.domain+"&areacode="+a.currentTarget.dataset.item.areacode
        });
    },
 
    searchfun: function(a) {
        var e = a.detail.value;
        this.setData({
            searchValue: e,
            isSearch: e.length > 0,
            isSearchEnd: !1
        }), e.length > 0 && this.getSearchDataList();
    },
    searchTap: function() {
        var e = this;
        if (0 == this.data.isSearch) this.setData({
            searchValue: "",
            isSearch: !1,
            isSearchEnd: !1
        }), wx.switchTab({
            url: "/pages/homepages/homepages"
        }); else {
            if (0 == this.data.searchValue.length) {
                if (this.data.defaulValueBool) {
                    var t = [ this.data.defaultValue ].concat(a(this.data.historySearch));
                    wx.setStorage({
                        key: "search-history-list",
                        data: t,
                        success: function(a) {
                            if ("setStorage:ok" == a.errMsg) {
                                var t = "/pages/homepages/search/result/result?search=" + e.data.defaultValue;
                                wx.navigateTo({
                                    url: t
                                });
                            }
                        }
                    });
                } else wx.showToast({
                    title: "请输入搜索内容",
                    icon: "none",
                    duration: 2e3,
                    mask: !0
                });
                return;
            }
            var s = [ this.data.searchValue ].concat(a(this.data.historySearch));
            wx.setStorage({
                key: "search-history-list",
                data: s,
                success: function(a) {
                    if ("setStorage:ok" == a.errMsg) {
                        var t = "/pages/homepages/search/result/result?search=" + e.data.searchValue;
                        wx.navigateTo({
                            url: t
                        });
                    }
                }
            }), this.setData({
                isSearch: !0
            });
        }
    },
 
    searchCleanTap: function() {
        this.setData({
            searchValue: "",
            isSearch: !1,
            isSearchEnd: !1,
            hosList: [],
            pkgList: []
        });
    },
    onShareAppMessage: function() {}
});